package com.nacrtstudio.webgiftshop.pages;

import net.sourceforge.htmlunit.corejs.javascript.regexp.SubString;

import org.apache.tapestry5.annotations.InjectPage;
import org.apache.tapestry5.annotations.Persist;
import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.ioc.annotations.Inject;
import org.apache.tapestry5.services.Request;

import com.nacrtstudio.webgiftshop.facade.Controller;
import com.nacrtstudio.webgiftshop.model.shop.Gift;

public class GiftInfo {
	@Inject
	private Request request;
	public void onActivate() {
		try {
			if (controller.getRequest()==null) {
	    		controller.setRequest(request);
			}
		} catch (Exception e) {
		}
	}

	@Persist
	private Gift gift;
	@InjectPage
	private StatusPage statusPage;
	@Inject
	private Controller controller;
	@Property
	private String imgPath;
	
	
	public Gift getGift() {
		return gift;
	}

	public void setGift(Gift gift) {
		this.gift = gift;
	}

	Object onActionFromAddToShoopingCard(Long id) {
		if (controller.getLoggedSignal()) {
			return controller.addGiftToCart(id);
		}
		statusPage.setMessage("Niste ulogovani");
		return statusPage;
	}
	
	public String imgUrlTransform(Gift gift){
		String string = gift.getImgPath();
//		return string.substring(0,14)+"big-"+string.substring(14, string.length());
		return string;
	}
	
	
	
	
	
	
	
	
	
	
	
}
